package io.gitee.dqcer.mcdull.uac.provider.system.service.impl;


import java.util.ArrayList;
import java.util.List;

import io.gitee.dqcer.mcdull.uac.provider.system.domain.CarVehicle;
import io.gitee.dqcer.mcdull.uac.provider.system.domain.vo.CarVehicleVO;
import io.gitee.dqcer.mcdull.uac.provider.system.mapper.CarVehicleMapper;
import io.gitee.dqcer.mcdull.uac.provider.system.mapper.SysUserMapper;
import io.gitee.dqcer.mcdull.uac.provider.system.service.ICarVehicleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * vehicleInfoService业务层处理
 *
 * @author ruoyi
 * @date 2023-12-10
 */
@Service
public class CarVehicleServiceImpl implements ICarVehicleService
{
    @Autowired
    private CarVehicleMapper carVehicleMapper;

    @Resource
    private SysUserMapper sysUserMapper;

    /**
     * 查询vehicleInfo
     *
     * @param vehicleId vehicleInfo主键
     * @return vehicleInfo
     */
    @Override
    public CarVehicle selectCarVehicleByVehicleId(Long vehicleId)
    {
        return carVehicleMapper.selectCarVehicleByVehicleId(vehicleId);
    }

    /**
     * 查询vehicleInfo列表
     *
     * @param carVehicle vehicleInfo
     * @return vehicleInfo
     */
    @Override
    public List<CarVehicleVO> selectCarVehicleList(CarVehicle carVehicle)
    {
        List<CarVehicleVO> voList = new ArrayList<>();
        List<CarVehicle> carVehicles = carVehicleMapper.selectCarVehicleList(carVehicle);
        for (CarVehicle vehicle : carVehicles) {
            CarVehicleVO vo = this.convertVO(vehicle);
            vo.setNickName(sysUserMapper.selectUserById(vo.getUserId()).getNickName());
            voList.add(vo);
        }
        return voList;
    }

    private CarVehicleVO convertVO(CarVehicle vehicle) {
        CarVehicleVO carVehicleVO = new CarVehicleVO();
        carVehicleVO.setVehicleId(vehicle.getVehicleId());
        carVehicleVO.setUserId(vehicle.getUserId());
        carVehicleVO.setBrand(vehicle.getBrand());
        carVehicleVO.setModel(vehicle.getModel());
        carVehicleVO.setVin(vehicle.getVin());
        carVehicleVO.setLicensePlate(vehicle.getLicensePlate());
        carVehicleVO.setColor(vehicle.getColor());
        carVehicleVO.setPurchaseDate(vehicle.getPurchaseDate());
        carVehicleVO.setYear(vehicle.getYear());
        carVehicleVO.setMileage(vehicle.getMileage());
        carVehicleVO.setManufacturer(vehicle.getManufacturer());
        carVehicleVO.setEngineNumber(vehicle.getEngineNumber());
        carVehicleVO.setFuelType(vehicle.getFuelType());
        carVehicleVO.setTransmissionType(vehicle.getTransmissionType());
        carVehicleVO.setStatus(vehicle.getStatus());
        carVehicleVO.setRegistrationDate(vehicle.getRegistrationDate());
        carVehicleVO.setValidityPeriod(vehicle.getValidityPeriod());
        carVehicleVO.setInsurancePeriod(vehicle.getInsurancePeriod());
        carVehicleVO.setImage(vehicle.getImage());
        carVehicleVO.setCreatedAt(vehicle.getCreatedAt());
        carVehicleVO.setUpdatedAt(vehicle.getUpdatedAt());
        carVehicleVO.setSearchValue(vehicle.getSearchValue());
        carVehicleVO.setCreateBy(vehicle.getCreateBy());
        carVehicleVO.setCreateTime(vehicle.getCreateTime());
        carVehicleVO.setUpdateBy(vehicle.getUpdateBy());
        carVehicleVO.setUpdateTime(vehicle.getUpdateTime());
        carVehicleVO.setRemark(vehicle.getRemark());
        carVehicleVO.setParams(vehicle.getParams());
        return carVehicleVO;
    }

    /**
     * 新增vehicleInfo
     *
     * @param carVehicle vehicleInfo
     * @return 结果
     */
    @Override
    public int insertCarVehicle(CarVehicle carVehicle)
    {
        return carVehicleMapper.insertCarVehicle(carVehicle);
    }

    /**
     * 修改vehicleInfo
     *
     * @param carVehicle vehicleInfo
     * @return 结果
     */
    @Override
    public int updateCarVehicle(CarVehicle carVehicle)
    {
        return carVehicleMapper.updateCarVehicle(carVehicle);
    }

    /**
     * 批量删除vehicleInfo
     *
     * @param vehicleIds 需要删除的vehicleInfo主键
     * @return 结果
     */
    @Override
    public int deleteCarVehicleByVehicleIds(Long[] vehicleIds)
    {
        return carVehicleMapper.deleteCarVehicleByVehicleIds(vehicleIds);
    }

    /**
     * 删除vehicleInfo信息
     *
     * @param vehicleId vehicleInfo主键
     * @return 结果
     */
    @Override
    public int deleteCarVehicleByVehicleId(Long vehicleId)
    {
        return carVehicleMapper.deleteCarVehicleByVehicleId(vehicleId);
    }
}

